<template>
  <view class="list">
    <list-item v-for="(v, i) in list" :key="i" :v="v" @click="goToDetail(v)"></list-item>
  </view>
</template>

<script>
  export default {
    onReachBottom() {
      if (this.total === this.list.length) {
        return;
      }
      this.queryData.pagenum++;
      this.getList()
    },
    onLoad(options) {
      const {
        name,
        query
      } = options;
      uni.setNavigationBarTitle({
        title: name || '详情列表'
      })
      this.queryData.query = query
      this.getList()
    },
    data() {
      return {
        // 查询参数
        queryData: {
          query: '',
          cid: '',
          pagenum: 1,
          pagesize: 10
        },
        // 列表
        list: [],
        // 总数据量
        total: 0
      };
    },
    methods: {
      goToDetail(v) {
        uni.navigateTo({
          url: '/subpkg/detail/detail?goods_id=' + v.goods_id
        })
      },
      async getList() {
        uni.showLoading({
          title: '数据加载中...'
        })
        const [error, resp] = await uni.request({
          url: 'https://www.uinav.com/api/public/v1/goods/search',
          data: this.queryData,
          methods: 'GET'
        })
        // 累加数据
        this.list = this.list.concat(resp.data.message.goods)
        this.total = resp.data.message.total
        uni.hideLoading()
      }
    }
  }
</script>

<style lang="scss">

</style>
